package DEEPERsource.DEEPERsource.source.preprocessing;

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import deeper.Protein;

/**
 * Implementation of preprocessor, intended to simplify
 * parsing task.
 * @author tfayruzo
 *
 */
public class DefaultPreprocessor implements Preprocessor {
	private static Log _log = LogFactory.getLog(DefaultPreprocessor.class);

	public Map<String,String> preprocessSentence(String sentence, Set<Protein> interactors, List<Protein> proteins) {
		Map<String, String> result = new HashMap<String, String>();
		Collections.sort(proteins);
		int offset = 0;
		/*//arguable tweaking. Removes leading section names of form 'OBJECTIVE :'. Executes only if we don't have protein in the beginning, 
		//thus exclude errorneous removing of protein name written in capitals.
		if(proteins.get(0).startOffset[0]>0){
			Pattern p = Pattern.compile("^[A_Z\\s\\d]+:\\s+");
			Matcher m = p.matcher(sentence);
			if(m.find()){
				_log.debug(m.group());
				sentence = sentence.replace(m.group(), "");
				result.put("sectionName", m.group());
				offset -= m.group().length(); 
			}
		}*/
		//substituting interacting protein names with unique ID's
		int c1 = 0, c2 = 0; //term index
		for(ListIterator<Protein> i = proteins.listIterator(); i.hasNext();){
			Protein prot = i.next();
			if(interactors.contains(prot)){
				String id = "ccoterm"+c1;
				int length = prot.endOffset[prot.endOffset.length-1] - prot.startOffset[0] + 1;
				prot.startOffset_mod = prot.startOffset[0] + offset;
				prot.endOffset_mod = prot.startOffset_mod + id.length()-1;
				prot.name_mod = id;
				sentence = sentence.substring(0,prot.startOffset_mod) + id + sentence.substring(prot.endOffset[prot.endOffset.length-1]+offset+1);
				offset += id.length() - length;
 				result.put(id, prot.name);
				/*//shortenings detection off
				Protein prot2 = null;
				if(i.hasNext() && sentence.length()>prot.endOffset_mod+1 && sentence.charAt(prot.endOffset_mod+1)=='/'){
					prot2 = i.next();
				}
				if(prot2 != null){
					Map<String,Object> ret = shorteningDetection(sentence, prot, prot2, interactors, c1, c2, id, result, offset);
					if(ret == null){
						i.previous();
						continue;
					}			
					offset = (Integer)ret.get("offset");
					c2 = (Integer)ret.get("c2");
					if(ret.get("c1")!=null)
						c1 = (Integer)ret.get("c1");
					sentence = (String)ret.get("sentence");
					System.out.println(sentence);
				}*/
				c1++;
			}			
		}
		sentence = htmlReplacements(sentence, interactors);
		sentence = referenceReplacement(sentence, interactors);
		result.put("sentence", sentence);
		return result;
	}
	
	private Map<String, Object> shorteningDetection(String sentence, Protein prot, Protein prot2, Set<Protein> interactors, int c1, int c2, String id, Map<String,String> result, int offset){
		//performing following optimization: if 2 protein names are separated with '/' and one is one-word and another is
		//more than one word, then it is shortening
		// 0 - not occur, 1 - complex,  2 - not complex
		Map<String, Object> ret = new HashMap<String, Object>();
		byte complex1 = 0, complexNext = 0, complexPrev = 0;;
		if(prot.name.contains(" "))
			complex1 = 1;
		else if (prot2.name.contains(" "))
			complex1 = 2;
		else
			return null;
		
		String termName = "ccoid";
		if(interactors.contains(prot2)){
			termName = "ccoterm";
			ret.put("c2", c2);
			c2 = c1;
			ret.put("c1", c2);
		}
		
		if((interactors.contains(prot2) && prot2.endOffset_mod == prot.startOffset_mod-2) ||
				(prot2.endOffset[0] == prot.startOffset[0]-2))
			if(prot2.name.contains(" "))
				complexPrev = 1;
			else
				complexPrev = 2;
		
		if((interactors.contains(prot2) && prot2.startOffset_mod == prot.endOffset_mod+2) ||
				(prot2.startOffset[0] == prot.endOffset[0]+2))
			if(prot2.name.contains(" "))
				complexNext = 1;
			else
				complexNext = 2;
		
		if(complex1==1 && complexNext==2){ // pComplex/_ => pComplex(ccoid) transformationType = 1
			if(interactors.contains(prot2))
				return null;
			String sid = "("+termName+c2+")";
			String shortening = prot2.name;
			sentence = sentence.replace(prot.name_mod+"/"+shortening, prot.name_mod+sid);
			offset += sid.length() - shortening.length() - 1;
			result.put(termName+c2, prot2.name);
			result.put("transformationType", "1");
		}else if(complex1 == 1 && complexPrev == 2){ // _/pComplex => pComplex(ccoid) transformationType = 2a, 2b
			boolean interactingProtein = interactors.contains(prot2);
			if(interactingProtein){
				int startOffset = prot2.startOffset[0];
				prot.startOffset_mod = startOffset;
				prot.endOffset_mod = startOffset + id.length();
				prot2.startOffset_mod = prot.endOffset_mod + 2;
				prot2.endOffset_mod = prot2.startOffset_mod + prot2.name_mod.length();
				String sid = "("+prot2.name_mod+")";
				sentence = sentence.replace(prot2.name_mod+"/"+prot.name_mod, prot.name_mod+sid);
				offset += 1;
				result.put("transformationType", "2a");
			}else{
				int startOffset = prot2.startOffset[0];
				prot.startOffset_mod = startOffset;
				prot.endOffset_mod = startOffset + id.length();
				String sid = "("+termName+c2+")";
				offset += sid.length() - prot2.name.length() - 1;
				sentence = sentence.replace(prot2.name+"/"+prot.name_mod, prot.name_mod+sid);
				result.put(termName+c2, prot2.name);
				c2++;
				result.put("transformationType", "2b");
			}					
		}else if(complex1 == 2 && complexNext == 1){// p/_ _ _ => ccoid(p) transformationType = 3
			if(interactors.contains(prot2))
				return null;
			String full = prot2.name;
			String sid = termName+c2;
			sentence = sentence.replace(prot.name_mod+"/"+full, sid+"("+prot.name_mod+")");
			offset += sid.length() - full.length() + 1;
			result.put(termName+c2, prot2.name);
			c2++;
			result.put("transformationType", "3");
		}else if(complex1 == 2 && complexPrev == 1){ // _ _ _/p => ccoid(p) transformationType = 4a, 4b
			boolean interactingProtein = interactors.contains(prot2);
			String sid = "("+prot.name_mod+")";
			if(interactingProtein){
				sentence = sentence.replace(prot2.name_mod+"/"+prot.name_mod, prot2.name_mod+sid);
				offset += 1;
				result.put("transformationType", "4a");
			}else{
				String full = prot2.name;
				String shortening = termName+c2;
				sentence = sentence.replace(full+"/"+prot.name_mod, shortening+sid);
				result.put(termName+c2, full);
				c2++;
				offset += shortening.length() - full.length() + 1;
				result.put("transformationType", "4b");
			}					
		}
		ret.put("sentence", sentence);
		ret.put("c2", c2);
		ret.put("offset", offset);
		return ret;
	}
	
	private void readjustProteinPositions(int[] oldInterval, int[] newInterval, Collection<Protein> proteins){
		int offset = newInterval[1]-newInterval[0] - oldInterval[1] + oldInterval[0];
		for(Protein p : proteins){
			if(p.startOffset_mod>oldInterval[1]){
				p.startOffset_mod += offset;
				p.endOffset_mod += offset;
			}
		}
	}
	
	private String htmlReplacements(String sentence, Collection<Protein> interactors){
		Pattern p = Pattern.compile("(&quot)|(&amp)|(&gt)|(&lt)");
		Matcher m = p.matcher(sentence);
		while(m.find()){
			String group = m.group();
			if(group.equals("&quot"))
				sentence = sentence.replace(group, "'");
			else if(group.equals("&amp"))
				sentence = sentence.replace(group, "&");
			else if(group.equals("&gt"))
				sentence = sentence.replace(group, ">");
			else if(group.equals("&lt"))
				sentence = sentence.replace(group, "<");
			readjustProteinPositions(new int[]{m.start(), m.end()}, new int[]{m.start(),m.start()+1},interactors);
			m = p.matcher(sentence);
		}
		return sentence;
	}
	
	private String findBoundary(int[] interval, String sentence){
		String begin = sentence.substring(0,interval[0]);
		String end = sentence.substring(interval[1]);
		int openBr1 = begin.lastIndexOf("(");
		int openBr2 = begin.lastIndexOf("[");
		char openBr, closeBr;
		if(openBr1<0 && openBr2<0){
			return sentence;
		}else if(openBr1>openBr2){
			openBr = '(';
			closeBr = ')';
		}else{
			openBr = '[';
			closeBr = ']';
		}
		CharacterIterator it = new StringCharacterIterator(begin);
		int counter = 0;
		int startIndex = 0;
		for(char c = it.last(); c != CharacterIterator.DONE; c = it.previous()){
			if(c == closeBr)
				counter--;
			if(c == openBr)
				counter++;			
			if(counter==1){
				startIndex = it.getIndex();
				break;
			}
		}
		it = new StringCharacterIterator(end);
		counter = 1;
		int endIndex = 0;
		for(char c = it.first(); c != CharacterIterator.DONE; c = it.next()){
			if(c == openBr)
				counter++;
			if(c == closeBr)
				counter--;
			if(counter==0){
				endIndex = it.getIndex();
				break;
			}
		}
		endIndex = begin.length() + interval[1] - interval[0] + 1 + endIndex;
		return sentence.substring(startIndex, endIndex);
	}
	
	public String referenceReplacement(String sentence, Collection<Protein> interactors){
		Pattern p = Pattern.compile("\\[[\\d,\\-\\s]+\\]");
		Matcher m = p.matcher(sentence);
		while(m.find()){
			String group = m.group();
			sentence = sentence.replace(group, "");
			readjustProteinPositions(new int[]{m.start(), m.end()}, new int[]{m.start(),m.start()},interactors);
		}
		
		p = Pattern.compile("(([A-Z]\\.\\s*)+[A-Z][a-z'-]+)|([A-Z][a-z'-]+, ([A-Z]\\.\\s*))");
		m = p.matcher(sentence);
		while(m.find()){
			String surroundingGroup = findBoundary(new int[]{m.start(),m.end()}, sentence);
			int start = sentence.indexOf(surroundingGroup);
			int[] oldBound = new int[]{start, start + surroundingGroup.length()};
			int[] newBound = new int[]{start, start};			
			sentence = sentence.replace(surroundingGroup, "");
			readjustProteinPositions(oldBound, newBound, interactors);
			m = p.matcher(sentence);
		}		
		return sentence;		
	}
		
	/*private static String expandFormula(String parOpen, String parClose, String sentence, String group) throws SentenceFormatException {
		Pattern open = null;
		if (parOpen.equals("(") || parOpen.equals("[")||parOpen.equals("{")) {
			open = Pattern.compile("\\".concat(parOpen));
		} else {
			open = Pattern.compile(parOpen);
		}
		Pattern close = null;
		if (parOpen.equals("(") || parOpen.equals("[")|| parOpen.equals("{")) {
			close = Pattern.compile("\\".concat(parClose));
		} else {
			close = Pattern.compile(parClose);
		}

		int numOpen = 0;
		int numClose = 0;
		Matcher mOpen = open.matcher(sentence);
		Matcher mClose = close.matcher(sentence);
		while (mOpen.find()) {
			numOpen++;
		}
		while (mClose.find()) {
			numClose++;
		}
		if (numOpen != numClose) {
			throw new SentenceFormatException(sentence.concat("\nSentence has ").concat(Integer.toString(numOpen).concat(" ").concat(parOpen))
					.concat(" and ").concat(Integer.toString(numClose).concat(" ").concat(parClose)));
		}

		mOpen = open.matcher(sentence.replace(group, ""));
		mClose = close.matcher(sentence.replace(group, ""));
		numOpen = 0;// count opening braces OUTSIDE the group
		numClose = 0;// count closing braces OUTSIDE the group
		while (mOpen.find()) {
			numOpen++;
		}
		while (mClose.find()) {
			numClose++;
		}
		while (numOpen != numClose) {
			if (numOpen > numClose) {// should extend group to right
				Pattern p = java.util.regex.Pattern.compile(parOpen);
				java.util.regex.Matcher m = p.matcher(sentence.substring(0, sentence.indexOf(group)));
				String openStr = ""; 
				while(m.find()){
					openStr = m.group();
				}
				//group = sentence.substring(sentence.substring(0, sentence.indexOf(group)).lastIndexOf(parOpen), sentence.indexOf(group))
				group = openStr.concat(group);
			} else {// should extend group to left
				group = group.concat(sentence.substring(sentence.indexOf(group) + group.length(), sentence.indexOf(parClose, sentence.indexOf(group)
						+ group.length())
						+ parClose.length()));
			}
			mOpen = open.matcher(sentence.replace(group, ""));
			mClose = close.matcher(sentence.replace(group, ""));
			numOpen = 0;
			numClose = 0;
			while (mOpen.find()) {
				numOpen++;
			}
			while (mClose.find()) {
				numClose++;
			}
		}
		return group;
	}

	private Map<String, String> preproc_internal(String sentence) throws SentenceFormatException{
		Map<String, String> result = new HashMap<String, String>();

		// remove list marks 1) 2) i) ii)
		//sentence = sentence.replaceAll("\\s\\d\\)", "");
		//sentence = sentence.replaceAll("\\si+\\)", "");

		// change chemical formulae to id's in order to simplify sentence
		//pattern represents some typical symbol combinations for formulae
		//(\\S\\())\\S*)|
		Pattern p = Pattern
				.compile("([^>\\s]*((\\d'-)|(\\d',)|(\\d,\\d)|(\\d,\\w)|(\\w,\\d)|([^>\\s]\\())\\S*)|(\\S*-\\S*-\\S*)");
				//.compile("(\\S*(\\d'-)|(\\d',)|(\\d,\\d)|(\\d,\\w)|(\\w,\\d)|(\\S*-\\S*-\\S*)");
		Matcher m = p.matcher(sentence);
		int i = 0;
		while (m.find()) {
			String group = m.group();
			// check parentheses pairs
			group = expandFormula("<ccoTerm( reaction=\\w+ role=\\w+ )*>", "</ccoTerm>", sentence, group);
			group = expandFormula("(", ")", sentence, group);
			group = expandFormula("[", "]", sentence, group);
			group = expandFormula("{", "}", sentence, group);

			// adjust formula boundaries
			if (group.startsWith("(")) {
				if (group.endsWith(")")) {
					group = group.substring(1, group.length() - 1);
				} else if (group.endsWith("),") || group.endsWith(").")) {
					group = group.substring(1, group.length() - 2);
				} else if (group.endsWith("-")) {
					group = group.substring(0, group.length() - 1);
				} else {
					group = group.substring(1);
				}
			}
			if (group.startsWith("[")) {
				if (group.endsWith("]")) {
					group = group.substring(1, group.length() - 1);
				} else if (group.endsWith("],") || group.endsWith("].")) {
					group = group.substring(1, group.length() - 2);
				} else if (group.endsWith("-")) {
					group = group.substring(0, group.length() - 1);
				} else {
					group = group.substring(1);
				}
			}
			
			if (group.startsWith("{")) {
				if (group.endsWith("}")) {
					group = group.substring(1, group.length() - 1);
				} else if (group.endsWith("},") || group.endsWith("}.")) {
					group = group.substring(1, group.length() - 2);
				} else if (group.endsWith("-")) {
					group = group.substring(0, group.length() - 1);
				} else {
					group = group.substring(1);
				}
			}

			if (group.endsWith(",") || (group.endsWith("."))) {
				group = group.substring(0, group.length() - 1);
			}
			
			String key = "ccoid";
			for(int k = 0;k<i;k++){
				key = key.concat("id");
			}

			group = group.replace("\\", "\\\\").replace("(", "\\(").replace(")", "\\)").replace("[", "\\[").replace("]", "\\]").replace("+", "\\+").replace("{", "\\{").replace("}", "\\}")
					.replace("*", "\\*").replace("?", "\\?").replace("&", "\\&").replace("$", "\\$");
			if (group.contains("<ccoTerm") && group.contains("</ccoTerm>")) {
				Pattern p2 = Pattern.compile("<ccoTerm( reaction=\\w+ role=\\w+ )*>");
				Matcher m2 = p2.matcher(group);
				m2.find();				
				sentence = sentence.replaceFirst(group, m2.group().concat(key).concat("</ccoTerm>"));
			} else {
				sentence = sentence.replaceFirst(group, key);
			}

			result.put(key, group.replaceAll("<ccoTerm( reaction=\\w+ role=\\w+ )*>", "").replace("</ccoTerm>", ""));
			m = p.matcher(sentence);
			i++;
		}
		//change ccoTerms with spaces
		p = Pattern.compile("<ccoTerm( reaction=\\w+ role=\\w+ )*>([^<]+)</ccoTerm>");
		m = p.matcher(sentence);
		while(m.find()){
			String data = m.group(2);
			if(data.contains(" ")){
				String key = "ccoid";
				for(int k = 0;k<i;k++){
					key = key.concat("id");
				}
				data = data.replace("\\", "\\\\").replace("(", "\\(").replace(")", "\\)").replace("[", "\\[").replace("]", "\\]").replace("+", "\\+").replace("{", "\\{").replace("}", "\\}")
						.replace("*", "\\*").replace("?", "\\?").replace("&", "\\&").replace("$", "\\$");
				sentence = sentence.replaceFirst(data, key);
				result.put(key, data);
				m = p.matcher(sentence);
				i++;
			}
		}
		
		// separate punctuation marks
		sentence = sentence.replace(",", " , ").replace(":", " : ").replace(";", " ; ").replace("(", " ( ").replace(")", " ) ").replace("\"", " \" ")
				.replace("'", " ' ").replace("[", " [ ").replace("]", " ] ").replaceAll("\\([^)]*[=+][^)]*?\\)", "").trim();
		if(sentence.endsWith(".")){
			sentence = sentence.substring(0, sentence.length() - 1);
		}
		sentence = sentence.concat(" .");
		
		//handle partially processed input
		p = Pattern
				.compile("(/)(?!(ccoTerm( reaction=\\w+ role=\\w+ )*>)|(NN)|(CC)|(CD)|(DT)|(EX)|(FW)|(IN)|(JJ)|(JJR)|(JJS)|(LS)|(MD)|(NN)|(NNS)|(NNP)|(NNPS)|(PDT)|(POS)|(PRP)|(PRP$)|(RB)|(RBR)|(RBS)|(RP)|(SYM)|(TO)|(UH)|(VB)|(VBD)|(VBG)|(VBN)|(VBP)|(VBZ)|(WDT)|(WP)|(WP$)|(WRB))");
		m = p.matcher(sentence);
		while (m.find()) {
			sentence = sentence.substring(0, m.start(1)).concat("\\\\").concat(sentence.substring(m.end(1), sentence.length()));
			m = p.matcher(sentence);
		}
		// transform structures like 'BPA- and BP-imprinted' to 'BPA-imprinted
		// and BP-imprinted'.
		// Take care of possible tag occurences
		p = Pattern.compile("([\\w\\d<>/]+)-\\s(,|(and)|(or))\\s([\\w\\d<>/]+)-([\\w\\d<>/]+)");
		m = p.matcher(sentence);
		while (m.find()) {
			String group = m.group();
			String type1 = m.group(1);
			String type2 = m.group(5);
			String type = m.group(6);
			String conj = m.group(2);
			sentence = sentence.replace(group, type1.concat("-").concat(type).concat(" ").concat(conj).concat(" ").concat(type2).concat("-").concat(
					type));
			m = p.matcher(sentence);
		}

		// divide structures like '<ccoTerm>CDK1</ccoTerm>-<ccoTerm>CDK2</ccoTerm>' to
		// <ccoTerm>CDK1</ccoTerm> and <ccoTerm>CDK2</ccoTerm>
		p = Pattern.compile("(<ccoTerm( reaction=\\w+ role=\\w+ )*>[^<]+</ccoTerm>)-(<ccoTerm( reaction=\\w+ role=\\w+ )*>[^<]+</ccoTerm>)");
		m = p.matcher(sentence);
		while (m.find()) {
			String exp1 = m.group(1);
			String exp2 = m.group(3);
			String change = exp1.concat(" and ").concat(exp2);
			sentence = sentence.substring(0, m.start()).concat(change).concat(sentence.substring(m.end()));
			m = p.matcher(sentence);
		}
		// divide structures like 'E/A-<ccoTerm>CDK2</ccoTerm>' to
		// 'E-<ccoTerm>CDK2</ccoTerm> and A-<ccoTerm>CDK2</ccoTerm>'
		p = Pattern.compile("(\\w)+\\\\(\\w)+(-<ccoTerm( reaction=\\w+ role=\\w+ )*>[^<]+</ccoTerm>)");
		m = p.matcher(sentence);
		while (m.find()) {
			String type1 = m.group(1);
			String type2 = m.group(2);
			String type = m.group(3);
			String change = type1.concat(type).concat(" and ").concat(type2).concat(type);
			sentence = sentence.substring(0, m.start()).concat(change).concat(sentence.substring(m.end()));
			m = p.matcher(sentence);
		}
		
		//split <ccoTerm>sdfsdf</ccoTerm>/<ccoTerm>sdvf<ccoTerm> to <ccoTerm>sdfsdf</ccoTerm> and <ccoTerm>sdvf<ccoTerm>
		p = Pattern.compile("(<ccoTerm( reaction=\\w+ role=\\w+ )*>[^<]+</ccoTerm>)\\\\\\\\(<ccoTerm( reaction=\\w+ role=\\w+ )*>[^<]+</ccoTerm>)");
		m = p.matcher(sentence);
		while (m.find()) {
			String entity1 = m.group(1);
			String entity2 = m.group(3);
			sentence = sentence.replace(m.group(), entity1.concat(" and ").concat(entity2));
		}
		
		p = Pattern.compile("(<ccoTerm( reaction=\\w+ role=\\w+ )*>[^<]+)</ccoTerm><ccoTerm( reaction=\\w+ role=\\w+ )*>([^<]+</ccoTerm>)");
		m = p.matcher(sentence);
		while (m.find()) {
			String entity1 = m.group(1);
			String entity2 = m.group(4);
			sentence = sentence.replace(m.group(), entity1.concat(entity2));
		}
		
		
		// expand tagged entities in order to caprure modifications, e.g.
		// 'E-<ccoTerm>CDK2</ccoTerm>' to '<ccoTerm>E-CDK2</ccoTerm>', etc.
		p = Pattern.compile("(([\\w\\d\\-'\\\\\\\\]+)(<ccoTerm( reaction=\\w+ role=\\w+ )*>))([^<]+</ccoTerm>)");
		m = p.matcher(sentence);
		while (m.find()) {
			String head = m.group(1);
			String newHead = m.group(2);
			String tag = m.group(3);
			sentence = sentence.replaceFirst(head, tag.concat(newHead));
		}
		p = Pattern.compile("<ccoTerm( reaction=\\w+ role=\\w+ )*>(([^<]+)</ccoTerm>([\\w\\d\\-'\\\\\\\\]+))");
		m = p.matcher(sentence);
		while (m.find()) {
			String tail = m.group(2);
			String entity = m.group(3);
			String postfix = m.group(4);
			sentence = sentence.replace(tail, entity.concat(postfix).concat("</ccoTerm>"));
		}

		sentence = sentence.replaceAll("[iI]n vivo", "in-vivo/RB").replaceAll("[iI]n vitro", "in-vitro/RB");
		p = Pattern.compile("<ccoTerm( reaction=\\w+ role=\\w+ )*>([\\S^-^<]+)</ccoTerm>");
		m = p.matcher(sentence);
		while(m.find()){
			String group = m.group();
			String inside = m.group(2);
			if(!inside.contains(" ")&&!inside.contains("-")){
				String newGroup = group.replace(inside, inside.concat("/NNP"));
				sentence = sentence.replace(group, newGroup);
			}
		}
		
		// check if we have occurences of different proteins. Otherwise return
		// null
		p = Pattern.compile("<ccoTerm( reaction=\\w+ role=\\w+ )*>([^<]+)</ccoTerm>");
		m = p.matcher(sentence);
		List<String> prots = new ArrayList<String>();
		while (m.find()) {
			String protein = m.group(2);
			if (protein.endsWith("\\person") || protein.endsWith("\\L") || protein.endsWith("\\l") || protein.endsWith("\\h")
					|| protein.endsWith("\\hour") || protein.endsWith("\\H") || protein.endsWith("\\min") || protein.endsWith("\\m")
					|| protein.endsWith("\\sec") || protein.endsWith("\\mg") || protein.endsWith("\\g")) {
				continue;
			}
			if (!prots.contains(protein)) {
				prots.add(protein);
			}
		}
		if (prots.size() < 1) {
			return null;
		}
		result.put("sentence", sentence);
		return result;
	}

	public Map<String, String> preprocessSentence(String sentence, List<Protein> proteins) {
		// TODO Auto-generated method stub
		return null;
	}*/
}
